package com.datang.litejvm.attribute;

import com.datang.litejvm.constant.ConstantPool;
import com.datang.litejvm.constant.ConstantUTF8Info;
import com.datang.litejvm.loader.ByteCodeIterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 顶风少年
 * @Description: 参数列表
 * @date: 18:29 2022/6/12
 **/
public class LocalVariableTable extends AttributeInfo {
    private List<LocalVariableItem> items = new ArrayList<LocalVariableItem>();

    public LocalVariableTable(int attrNameIndex, String attrNameValue, int attrLen) {
        super(attrNameIndex, attrNameValue, attrLen);
    }

    public void parse(ByteCodeIterator iter, ConstantPool pool) {
        //成员个数
        int localVariableLength = iter.nextU2ToInt();
        for (int a = 0; a < localVariableLength; a++) {
            LocalVariableItem localVariableItem = new LocalVariableItem();
            int startPC = iter.nextU2ToInt();
            int length = iter.nextU2ToInt();
            int localVariableNameIndex = iter.nextU2ToInt();
            int descIndex = iter.nextU2ToInt();
            int index = iter.nextU2ToInt();
            localVariableItem.setStartPC(startPC);
            localVariableItem.setLength(length);
            localVariableItem.setNameIndex(localVariableNameIndex);
            localVariableItem.setDescIndex(descIndex);
            localVariableItem.setIndex(index);
            items.add(localVariableItem);
        }
    }
}
